﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using FitAutomation.Client;

namespace FitAutomation
{
	public static class FitAutomationFacade
	{
//		static FitAutomationHost _host;
//		public static FitAutomationHost Host
//		{
//			get { return _host ?? (_host = TryConnectToExistingHost() ?? CreateHost()); }
//		}
//
//		static FitAutomationHost TryConnectToExistingHost()
//		{
//			return null;
//		}
//
//		static FitAutomationHost CreateHost()
//		{
//			var host=  new FitAutomationHost();
//			host.StartListening();
//			return host;
//		}

		public static void RegisterProcess()
		{
			RegisterProcess(null);
		}

		public static void RegisterProcess(Identifier id)
		{
			var process = Process.GetCurrentProcess();
			if(id==null)
			{
				id = new Identifier(process.ProcessName);
			}
			Client.Channel.RegisterProcess(new ProcessIdentifier(process, id));
		}

		public static void RegisterObject(Identifier id, object obj)
		{
		}

		static FitAutomationClient _client;

		static FitAutomationClient Client
		{
			get
			{
				if (_client == null)
				{
					_client = new FitAutomationClient();
				}
				return _client;
			}
		}

		public static int HostProcessId
		{
			get
			{
				return Client.Channel.GetHostProcessId();
			}
		}

		public static IEnumerable<ProcessIdentifier> GetRegisteredProcesses()
		{
			return Client.Channel.GetRegisteredProcesses();
		}
	}
}
